//
//  AppGroupStorage.m
//  EDPClient
//
//  Created by hu on 2024/12/13.
//

#import "AppGroupStorage.h"

@interface AppGroupStorage ()<RCTBridgeModule>

@end

@implementation AppGroupStorage
RCT_EXPORT_MODULE()

- (dispatch_queue_t)methodQueue
{
    return dispatch_get_main_queue();
}

RCT_EXPORT_METHOD(setItem:(NSString *)key value:(id)value)
{
    NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.EDPClient"];
    [defaults setObject:value forKey:key];
    [defaults synchronize];
}

RCT_EXPORT_METHOD(getItem:(NSString *)key resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
    NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.yourcompany.EDPClient"];
    id value = [defaults objectForKey:key];
    if (value) {
        resolve(value);
    } else {
        reject(@"E_ITEM_NOT_FOUND", @"Item not found", nil);
    }
}

@end
